Fix z-fighting and performance issues in 2D infinite scroll mode #12488
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request addresses both performance issues and zIndex issues in 2D infinite scroll mode.
Currently, the
execute2DViewportCommands
function clonescamera.position
so that the camera's x and y positions can be modified to enable infinite scrolling (i.e., rendering another copy of the map to the side). At the end ofexecute2DViewportCommands
, the camera's position is reset to the copy that was created earlier, because the camera modifications made were solely for rendering -- the camera is not actually intended to move. However, it appears that copying the previous camera z position (which is not modified inexecute2DViewportCommands
for infinite scroll rendering) resets changes made inexecuteCommands
to avoid z-fighting:cesium/packages/engine/Source/Scene/Scene.js
Lines 2614 to 2617 in 47b5d29
This pull request fixes this issue by only resetting the x and y values of the camera, rather than the entire position object. This fixes z-fighting reported in #8302 (zIndex Sandcastle):
Additionally, this pull request removes an extraneous
clone()
operation on the frustum. Thefrustum
variable is cloned from the camera on initialization, and thus does not need to be recloned later:cesium/packages/engine/Source/Scene/Scene.js
Line 3177 in 31670c1
These two changes also resolve some performance issues in 2D infinite scroll mode, for reasons that are not entirely clear to me. See the following screen recordings. In the Before recording, the FPS while panning drops from a steady ~100fps to around ~75fps. In the After recording, the FPS starts substantially higher, around ~140fps, and drops to only ~130fps.
Before Change
CleanShot.2025-02-19.at.12.22.32.mp4
After Change
CleanShot.2025-02-19.at.12.23.03.mp4
I am not clear on exactly where this performance hit is coming from, but the improvements appear to be even more noticeable on a lower-spec machine (where panning performance goes from ~30fps before the change to a steady ~90fps after the change).
Issue number and link
zIndex Issue: #8302
Likely related performance issue: #5026
Testing plan
I have tested that this fixes both the zIndex and performance issues on a variety of machines using this zIndex Sandcastle.
Author checklist
CONTRIBUTORS.md
CHANGES.md
with a short summary of my change